package com.googlecode.ddplan.dwr.domain;

import com.googlecode.ddplan.PDDLName;
import com.googlecode.ddplan.PDDLState;
import com.googlecode.ddplan.PDDLType;

@PDDLType
public class Box {
	@PDDLName
	private String name;

	private Box upperBox;

	public Box(String name) {
		this.name = name;
	}

	public boolean hasUpper() {
		return upperBox != null;
	}

	public Box getUpperBox() {
		return upperBox;
	}

	public void put(Box box) {
		upperBox = box;
	}

	public void free() {
		this.upperBox = null;
	}

	@PDDLState
	public boolean on(Box box) {
		if (!box.hasUpper()) {
			return false;
		}
		return box.upperBox.equals(this);
	}

	@PDDLState
	public boolean in(Pile pile) {
		return pile.contains(this);
	}

	@PDDLState
	public boolean top(Pile pile) {
		return in(pile) && !hasUpper();
	}

}
